package The07;

/**
 * @Author XiaoKe
 * @Date 2020/4/28 20:42
 * @Description Object类提供的"浅克隆"
 */
class Address {
    String detail;
    public Address(String detail) {
        this.detail = detail;
    }
}

class User implements Cloneable {
    int age;
    Address address;
    public User(int age) {
        this.age = age;
        address = new Address("潮州");
    }
    // 通过调用super.clone()来实现clone()方法
    @Override
    protected User clone() throws CloneNotSupportedException {
        return (User) super.clone();
    }
}

public class CloneTest {

    public static void main(String[] args) throws CloneNotSupportedException {
        User u1 = new User(22);
        // 克隆得到副本
        User u2 = u1.clone();
        // 判断u1，u2是否相同
        System.out.println(u1 == u2);
        // 判断u1，u2的Address是否相同
        System.out.println(u1.address == u2.address);
    }
}
